package com.tanhua.autoconfig;

import com.tanhua.autoconfig.properties.*;
import com.tanhua.autoconfig.template.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;


//相当于将SmsProperties交给容器
@EnableConfigurationProperties(
    {
            SmsProperties.class,
            OssProperties.class,
            AipFaceProperties.class,
            HuanXinProperties.class,
            GreenProperties.class
    }
)
public class TanhuaAutoConfiguration {

    //@Bean：如果有参数，从容器中查找对象，调用方法
    @Bean
    public SmsTemplate smsTemplate(SmsProperties properties) {
        return new SmsTemplate(properties);
    }

    @Bean
    public OssTemplate ossTemplate(OssProperties properties){
        return new OssTemplate(properties);
    }

    @Bean
    public AipFaceTemplate aipFaceTemplate(AipFaceProperties properties) {
        return new AipFaceTemplate(properties);
    }

    @Bean
    public HuanXinTemplate huanXinTemplate(HuanXinProperties properties) {
        return new HuanXinTemplate(properties);
    }

    /**
     * 在自动装配时，指定条件
     *  ConditionalOnProperty：
     *     prefix： 查找配置文件中已tanhua.green开头的配置
     *     value：查找一个属性enable
     *     havingValue：当tanhua.green.enable = true
     *    *完成自动装配
     */
    @Bean
    @ConditionalOnProperty(prefix = "tanhua.green",value = "enable", havingValue = "true")
    public AliyunGreenTemplate aliyunGreenTemplate(GreenProperties properties) {
        return new AliyunGreenTemplate(properties);
    }
}
